<template>
  <div class="table-wrapper track-table">
    <div class="search-container">
      <div class="search-wrapper">
        <span class="label">校区：</span>
        <el-select size="mini" v-model="params.xq_id" placeholder="请选择校区">
          <el-option v-for="item in xqList" :key="item.text" :label="item.text" :value="item.value"></el-option>
        </el-select>
      </div>
      <div class="search-wrapper">
        <span class="label">开始时间：</span>
        <el-date-picker
          size="mini"
          v-model="params.start_date"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择开始时间"
        >
        </el-date-picker>
      </div>
      <div class="search-wrapper">
        <span class="label">结束时间：</span>
        <el-date-picker
          size="mini"
          v-model="params.end_date"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择结束时间"
        >
        </el-date-picker>
      </div>
      <div class="search-wrapper">
        <span class="label">学工号：</span>
        <el-input v-model="params.badge_number" size="mini" class="common-input" placeholder="请输入学工号"></el-input>
      </div>
    </div>
    <div class="search-container">
      <div class="search-wrapper">
        <span class="label">姓名：</span>
        <el-input v-model="params.fullname" size="mini" class="common-input" placeholder="请输入姓名"></el-input>
      </div>
      <div class="search-wrapper">
        <el-button @click="getStuTrack" icon="el-icon-search" size="mini" >查询</el-button>
      </div>
    </div>
    <el-table
      :data="data"
      border
      height="calc(100% - 200px)"
      style="width: 100%">
      <el-table-column
        prop="badge_number"
        label="学工号">
      </el-table-column>
      <el-table-column
        prop="fullname"
        label="姓名">
      </el-table-column>
      <el-table-column
        prop="ly_name"
        label="楼宇">
      </el-table-column>
      <el-table-column
        prop="created_at"
        label="时间">
      </el-table-column>
      <el-table-column
        prop="mobile"
        label="电话">
      </el-table-column>
    </el-table>
<!--    <div class="el-pagination is-background">-->
<!--      <button type="button" @click="prevPage" class="btn-prev">-->
<!--        <i class="el-icon el-icon-arrow-left"></i>-->
<!--      </button>-->
<!--      <button type="button" class="btn-next" @click="nextPage">-->
<!--        <i class="el-icon el-icon-arrow-right"></i>-->
<!--      </button>-->
<!--    </div>-->
  </div>
</template>

<script>
import portal from '@/api/portal'

export default {
  name: 'TrackTable',
  data () {
    return {
      loading: false,
      params: {
        page: 1,
        total: 20000,
        fullname: null,
        badge_number: null,
        start_date: null,
        end_date: null,
        xq_id: null
      },
      xqList: [
        {
          text: '良乡校区',
          value: 1
        },
        {
          text: '中关村校区',
          value: 2
        }],
      data: []
    }
  },
  created () {
  },
  computed: {
  },
  mounted () {
  },
  methods: {
    async getStuTrack () {
      if (!this.params.xq_id) {
        this.$message.warning('请选择校区')
        return
      }
      if (!this.params.start_date) {
        this.$message.warning('请选择开始时间')
        return
      }
      if (!this.params.end_date) {
        this.$message.warning('请选择结束时间')
        return
      }
      this.loading = true
      const result = await portal.getStuTrack(this.params)
      if (result.data) {
        this.data = result.data
        this.params.total = result.data.total
        this.loading = false
      }
    },
    prevPage () {
      if (this.params.page > 1) {
        this.params.page--
        this.getStuTrack()
      }
    },
    nextPage () {
      if (this.data.length > 0) {
        this.params.page++
        this.getStuTrack()
      }
    }
  }
}
</script>

<style scoped lang="scss">

</style>
